package com.xauto.pioneer.appuser.model;

import android.content.Context;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**车辆计费规则模型
 * Created by Ellis.Li on 2017/5/12.
 */
@Table(name = "table_bill_rule")
public class BillRule extends BaseModel<BillRule> {

    /** 计费规则ID*/
    @Id(column = "billing_rules_id")
    public String billing_rules_id;
    /** 车辆等级ID*/
    public String car_group_id;
    /** 当前日期类型(1-平日/2-周末/3-节假期)*/
    public String date_type;
    /** 片段序列*/
    public String sort_order;
    /** 开始时间*/
    public String start_time;
    /** 结束时间*/
    public String end_time;
    /** 当前时段公里计费金额*/
    public String kilometre_value;
    /** 当前时段时间计费金额*/
    public String run_time_value;
    /** 当前时段消耗计费金额*/
    public String energy_value;

    public String getBilling_rules_id() {
        return billing_rules_id;
    }

    public void setBilling_rules_id(String billing_rules_id) {
        this.billing_rules_id = billing_rules_id;
    }

    public String getCar_group_id() {
        return car_group_id;
    }

    public void setCar_group_id(String car_group_id) {
        this.car_group_id = car_group_id;
    }

    public String getDate_type() {
        return date_type;
    }

    public void setDate_type(String date_type) {
        this.date_type = date_type;
    }

    public String getSort_order() {
        return sort_order;
    }

    public void setSort_order(String sort_order) {
        this.sort_order = sort_order;
    }

    public String getStart_time() {
        return start_time;
    }

    public void setStart_time(String start_time) {
        this.start_time = start_time;
    }

    public String getEnd_time() {
        return end_time;
    }

    public void setEnd_time(String end_time) {
        this.end_time = end_time;
    }

    public String getKilometre_value() {
        return kilometre_value;
    }

    public void setKilometre_value(String kilometre_value) {
        this.kilometre_value = kilometre_value;
    }

    public String getRun_time_value() {
        return run_time_value;
    }

    public void setRun_time_value(String run_time_value) {
        this.run_time_value = run_time_value;
    }

    public String getEnergy_value() {
        return energy_value;
    }

    public void setEnergy_value(String energy_value) {
        this.energy_value = energy_value;
    }

    @Override
    public BillRule parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            billing_rules_id = jsonObject.optString("billing_rules_id");
            car_group_id = jsonObject.optString("car_group_id");
            date_type = jsonObject.optString("date_type");
            sort_order = jsonObject.optString("sort_order");
            start_time = jsonObject.optString("start_time");
            end_time = jsonObject.optString("end_time");
            kilometre_value = jsonObject.optString("kilometre_value");
            run_time_value = jsonObject.optString("run_time_value");
            energy_value = jsonObject.optString("energy_value");
            return this;
        }
        return null;
    }
    @Override
    public boolean equals(Object o) {
        if (((BillRule)o).billing_rules_id.equals(billing_rules_id)){
            return true;
        }
        return false;
    }

    public void saveDb(Context mContext, BillRule billRule) {
        FinalDb finalDb = FinalDb.create(mContext);
        finalDb.deleteByWhere(BillRule.class, "billing_rules_id = \""+billRule.billing_rules_id+"\"");
        finalDb.save(billRule);
    }
}
